/**
 * 
 */
package fbv.commun.excecoes;

import java.util.ResourceBundle;

/**
 * @author mgrb
 *
 */
public class FBVException extends Exception {
	
	public FBVException(String msg) {
		super(msg);
	}
	
	public FBVException(String bundle, String msgKey, Throwable ex) {
		super(ResourceBundle.getBundle(bundle).getString(msgKey), ex);
	}
	
	public FBVException(String bundle, String msgKey, String[] complementos, Throwable ex) {
		super(comporMensagem(ResourceBundle.getBundle(bundle).getString(msgKey), complementos), ex);
	}
	
	public FBVException(String bundle, String msgKey) {
		super(ResourceBundle.getBundle(bundle).getString(msgKey));
	}
	
	public FBVException(String bundle, String msgKey, String[] complementos) {
		super(comporMensagem(ResourceBundle.getBundle(bundle).getString(msgKey), complementos));
	}
	
	static private String comporMensagem(String msgBase, String[] complementos) {
		for (int i = 0; i < complementos.length; i++) {
			msgBase = msgBase.replaceAll("\\{"+i+"\\}", complementos[i]);
		}
		return msgBase;
	}
}
